<?php

namespace app\merchant\controller\market;

use app\merchant\controller\Base;
use app\merchant\model\Setting as SettingModel;
use app\merchant\model\user\PointsLog as PointsLogModel;

/**
 * 积分管理
 * Class Points
 * @package app\store\controller\market
 */
class Points extends Base
{

    /**
     * 积分设置详情
     * @return array|bool|mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {

        $values = SettingModel::getItem('points');
        return $this->renderSuccess($values,"查询成功");

    }

    
    /**
     * 积分设置
     * @return array|bool|mixed
     * @throws \think\exception\DbException
     */
    public function set()
    {

        $model = new SettingModel;
        if ($model->edit('points', $this->postData())) {
            return $this->renderSuccess([],'操作成功');
        }
        return $this->renderError([],$model->getError() ?: '操作失败');
    }

    /**
     * 积分明细
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function log()
    {
        // 积分明细列表
        $model = new PointsLogModel;
        $list = $model->getList($this->request->param());
        return $this->fetch('log', compact('list'));
    }

}